<template>
	<view class="mainpadding">
		<view class="margin_top pdl">
			<view class="xiaohei main_size">补卡原因</view>
			<textarea class="margin_top xiaohei main_size" style="width: 100%;height: 150rpx;" placeholder="请输入补卡原因" v-model="reason"/></textarea>
		</view>
		<view class="xiaohei margin_top main_size">其他信息</view>
		<view class="flexleft flex_wrap">
			<view class="flexcenter margin_top" style="width: 25%;" v-for="(item,index) in upImg_text" :key="index">
				<view class="tupian dingwei">
					<image :src="item" mode=""></image>
					<view class="shanchu" @click="deleimgae(index)"></view>
				</view>
			</view>
			<view class="flexcenter margin_top" style="width: 25%;">
				<view class="tupian" @click="uploadImg" v-if="upImg_text.length>=4?false:true">
					<image src="@/static/upimg.png" mode=""></image>
				</view>
			</view>
		</view>
		<view class="mainpadding_top gudingdb">
			<view class="submitbtn" @click="submit">确认提交</view>
		</view>
		<timePicker :messageTime="messageTime" @timeConfirm="timeConfirm" @timecancel="timecancel"></timePicker>
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				upImg: [], //图片路径
				upImg_text: [], //图片路径
				reason:"",
				listid:""
			}
		},
		onLoad(options) {
			this.listid = options.id
		},
		methods: {
			submit(){
				if (this.reason == "") {
					httpRequest.toast("请输入补卡原因")
					return false
				}
				httpRequest.request('/api/Companydk/addCompanyDkbk', 'GET', {
					company_dkrecord_id: this.listid,
					reason: this.reason,
					images:this.upImg.join()
				}, false, false, true).then(res => {
					httpRequest.toast(res.msg)
					if (res.code == 1) {
						setTimeout(() => {
							uni.navigateBack(1)
						}, 1000)
					}
				})
			},
			// 删除照片
			deleimgae(index) {
				this.upImg.splice(index, 1)
				this.upImg_text.splice(index, 1)
			},
			// 上传多张照片
			uploadImg() {
				let _this = this;
				let upImgs = _this.upImg;
				let num = 4 - upImgs.length;
				if (num <= 0) {
					return false;
				}
				uni.showActionSheet({
					itemList: ['相机', '相册'],
					success: function(res) {
			
						// 选择相机走0
						if (res.tapIndex == 0) {
							httpRequest.chooseImage(num, ['camera']).then(res => {
								for (var i = 0; i < res.length; i++) {
									_this.uploadImageService(res[i], _this.upImg,_this.upImg_text)
								}
							}).catch(err => {});
						}
						// 选择相册走1
						if (res.tapIndex == 1) {
							httpRequest.chooseImage(num, ['album']).then(res => {
								for (var i = 0; i < res.length; i++) {
			
									_this.uploadImageService(res[i], _this.upImg,_this.upImg_text)
								}
							}).catch(err => {});
						}
					},
					fail: function(res) {}
				});
			},
			// 详情转载
			uploadImageService(url, upImg,upImg_text) {
				let _this = this;
				httpRequest.uploadFile('/api/common/upload', url).then(res => {
					let image_item = res.fullurl;
					let image = res.url;
					upImg.push(image);
					upImg_text.push(image_item);
				}).catch(err => {});
			},
		}
	}
</script>

<style scoped lang="scss">
.tupian {
		width: 147rpx;
		height: 147rpx;
		border-radius: 14rpx;

		image {
			width: 147rpx;
			height: 147rpx;
			border-radius: 14rpx;
		}
	}
	.shanchu {
		width: 32rpx;
		height: 32rpx;
		position: absolute;
		top: 0;
		right: 0;
		background-size: 100% 100%;
		background-image: url('@/static/shanchu1.png');
	}
</style>
